Release 10.1A: OpenEdge Getting Started:
Object-oriented Programming


Using the INTERFACE construct

An interface is a special type of class that defines only method names and signatures, along with any temp-table and ProDataSet definitions used as parameters to those methods. The interface definition specifies a main block that begins with an INTERFACE statement that names the interface. Only one interface can be defined per source file. An interface source file has a .cls file extension like any other class, and its filename must match the interface name defined in the INTERFACE statement. The INTERFACE statement must be the first statement in the interface. The last statement in an interface must be the END INTERFACE statement, which terminates the main block of the interface. An interface compiles to r-code like any other class.

Interfaces are always publicly scoped and available to all other classes and procedures within an application. Thus, an interface is the way to enforce a common set of methods for related objects. All objects that implement the same interface are guaranteed to support the common set of methods defined by the interface.

The main block of the interface contains statements that specify the method names and signatures that any class implementing the interface must define. Interfaces do not contain any data members but might contain temp-table and ProDataSet definitions that are used for parameters in specified method prototypes. No allocation is associated with these definitions. These temp-table and ProDataSet definitions must be specified before any method prototypes in the main block of the interface. Any class implementing an interface with temp-table or ProDataSet parameters must repeat those definitions within the class.

When compiling a class that implements an interface with temp-table or ProDataSet parameters, the definition of a given temp-table or ProDataSet in the implementing class must be compatible with the definition of the corresponding temp-table or ProDataSet in the interface. The compiler's compatibility rules are the same as those enforced when passing temp-table or ProDataSet parameters:

This is the syntax for defining an interface:

Syntax
INTERFACE type-name : 
    [ { temp-table | ProDataSet } ... ] 
    [ method ... ] 
END [ INTERFACE ] . 

Element descriptions for this syntax diagram follow:

type-name

A character string that identifies the type name for an interface definition. This character string has the following syntax:

Syntax
[package.]interface-name 

package

A character string that specifies a period-separated list of components that, along with interface-name, uniquely identify the interface among all classes and interfaces. The components are based on a valid directory pathname relative to PROPATH, where each component maps to a directory level in the path and each forward or backward slash separator in the path is replaced with a period (.). If specified, the relative pathname represented by package specifies the location of the class file that contains the interface definition. Any package specification must remain constant between compile time and run time.

Note: Do not place a class file in a directory whose name contains a period (.) character. Progress interprets the component after the period as another directory level and will therefore not find the referenced class file.

interface-name

A character string that specifies an interface name. This name must match the name of a class file (excluding the .cls or .r extension) that contains the definition for the specified interface. This class file must be located in the relative path represented by package, if specified. The interface-name must begin with an alphabetic character and it cannot contain a period. This name thus represents the unqualified name of the defined interface. Do not specify an interface name using a Progress reserved keyword or built-in Progress data type name, such as INTEGER.

If package or interface-name contains embedded spaces, you must enclose the entire type name specification in quotes.

For example, an interface with the type name topdir.subdir.SomeInterface must be found, at compile-time, as the source file SomeInterface.cls, in the directory topdir/subdir relative to the PROPATH. If the interface is compiled and saved, its r-code must be found at run time in the file SomeInterface.r and in the same directory path, topdir/subdir, relative to the PROPATH.

Note: The requirement to maintain a constant relative path between compile time and run time applies only to class files (not to procedure files).

temp-table | ProDataSet

The interface must supply temp-table and ProDataSet definitions for any temp-tables and ProDataSets used as parameters to methods defined for the interface. These are data definitions only. The class that implements this interface must define a data member that matches each data definition in the interface.

method

Specifies each method of the class. Each method is specified by a single METHOD statement, a prototype with a signature, but with no implementation and no END METHOD statement. All methods are public and a PUBLIC access mode must be explicitly specified for each method prototype contained in an interface file. Interfaces cannot contain constructors or destructors. The class that implements this interface must fully define a corresponding method that matches each method prototype in the interface.


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095